//
//  MyViewController.m
//  XRSquare
//
//  Created by UaenaMo on 2018/7/26.
//  Copyright © 2018年 UaenaMo. All rights reserved.
//

#import "MyViewController.h"
#import "UserTableViewCell.h"
#import "TextContentTableViewCell.h"

#import "PreviewViewController.h"
#import "HuiyuanViewController.h"
#import "InviteViewController.h"
#import "PingjiaViewController.h"
#import "ShezhiViewController.h"
#import "ShoucangViewController.h"
#import "SixinViewController.h"
#import "TrustViewController.h"
#import "WocanyudeViewController.h"
#import "WofabudeViewController.h"
#import "WodejinengViewController.h"
#import "YonghusousuoViewController.h"


@interface MyViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView * contentTableView;
    NSDictionary * userData;
}
@end

@implementation MyViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = NO;
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.hidden = YES;

    
    contentTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStylePlain];
    contentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    contentTableView.delegate = self;
    contentTableView.dataSource = self;
    [self.view addSubview:contentTableView];
    
    [self request];
}

-(void)request
{
    [NetRequestCenter userInfoResult:^(BOOL success, NSDictionary *resultDic) {
        NSLog(@"%@",resultDic);
        if (success) {
            userData = [resultDic objectForKey:@"data"];
            [contentTableView reloadData];
        }
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 13;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        return [UserTableViewCell height];
    }
    else if (indexPath.row == 5)
    {
        return 5;
    }
    else
    {
        return [TextContentTableViewCell height];
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        static NSString * identifer = @"identifer";
        UserTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifer];
        if (!cell) {
            cell = [[UserTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
        }
        [cell loadData:userData];
        return cell;
    }
    else if (indexPath.row == 5)
    {
        static NSString * identifer = @""; // 昵称？
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifer];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
        }
        cell.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        return cell;
    }
    else
    {
        static NSString * identifer = @"conten";
        TextContentTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifer];
        if (!cell) {
            cell = [[TextContentTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
        }
        
        if (indexPath.row == 1)
        {
            [cell loadString:@"邀请好友" iamge:[UIImage imageNamed:@"邀请好友"]];
        }
        else if (indexPath.row == 2)
        {
            [cell loadString:@"信任与验证" iamge:[UIImage imageNamed:@"信任与认证"]];
        }
        else if (indexPath.row == 3)
        {
            [cell loadString:@"评价" iamge:[UIImage imageNamed:@"评价"]];
        }
        else if (indexPath.row == 4)
        {
            [cell loadString:@"用户搜索与添加" iamge:[UIImage imageNamed:@"用户搜索及添加"]];
        }
        else if (indexPath.row == 6)
        {
            [cell loadString:@"私信" iamge:[UIImage imageNamed:@"私信"]];
        }
        else if (indexPath.row == 7)
        {
            [cell loadString:@"收藏" iamge:[UIImage imageNamed:@"收藏"]];
        }
        else if (indexPath.row == 8)
        {
            [cell loadString:@"我的技能" iamge:[UIImage imageNamed:@"我的技能"]];
        }
        else if (indexPath.row == 9)
        {
            [cell loadString:@"我参与的" iamge:[UIImage imageNamed:@"我参与的"]];
        }
        else if (indexPath.row == 10)
        {
            [cell loadString:@"我发布的" iamge:[UIImage imageNamed:@"我发布的"]];
        }
        else if (indexPath.row == 11)
        {
            [cell loadString:@"会员" iamge:[UIImage imageNamed:@"会员"]];
        }
        else if (indexPath.row == 12)
        {
            [cell loadString:@"设置" iamge:[UIImage imageNamed:@"设置"]];
        }
        return cell;
    }
}

-(BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 5)
    {
        return NO;
    }
    else
    {
        return YES;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden = YES;
    if (indexPath.row == 0)
    {
        PreviewViewController * edit = [[PreviewViewController alloc]init];
        [self.navigationController pushViewController:edit animated:YES];
    }
    else if (indexPath.row == 1)
    {
        InviteViewController * invite = [[InviteViewController alloc]init];
        [self.navigationController pushViewController:invite animated:YES];
    }
    else if (indexPath.row == 2)
    {
        TrustViewController * trust = [[TrustViewController alloc]init];
        [self.navigationController pushViewController:trust animated:YES];
    }
    else if (indexPath.row == 3)
    {
        PingjiaViewController * comment = [[PingjiaViewController alloc]init];
        comment.title = [NSString stringWithFormat:@"%@ 的评价",[userData objectForKey:@"Name"]];
        [self.navigationController pushViewController:comment animated:YES];
    }
    else if (indexPath.row == 4)
    {
        YonghusousuoViewController * yonghusousuo = [[YonghusousuoViewController alloc]init];
        [self.navigationController pushViewController:yonghusousuo animated:YES];
    }
    else if (indexPath.row == 6)
    {
        SixinViewController * comment = [[SixinViewController alloc]init];
        [self.navigationController pushViewController:comment animated:YES];
    }
    else if (indexPath.row == 7)
    {
        ShoucangViewController * comment = [[ShoucangViewController alloc]init];
        [self.navigationController pushViewController:comment animated:YES];
    }
    else if (indexPath.row == 8)
    {
        WodejinengViewController * comment = [[WodejinengViewController alloc]init];
        [self.navigationController pushViewController:comment animated:YES];
    }
    else if (indexPath.row == 9)
    {
        WocanyudeViewController * comment = [[WocanyudeViewController alloc]init];
        [self.navigationController pushViewController:comment animated:YES];
    }
    else if (indexPath.row == 10)
    {
        WofabudeViewController * comment = [[WofabudeViewController alloc]init];
        [self.navigationController pushViewController:comment animated:YES];
    }
    else if (indexPath.row == 11)
    {
        HuiyuanViewController * comment = [[HuiyuanViewController alloc]init];
        [self.navigationController pushViewController:comment animated:YES];
    }
    else
    {
        ShezhiViewController * comment = [[ShezhiViewController alloc]init];
        [self.navigationController pushViewController:comment animated:YES];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
